package com.ys.service.mail.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ys.entity.mail.MailTag;
import com.ys.entity.sys.TsUserChange;
import com.ys.mapper.mail.MailTagMapper;
import com.ys.service.mail.MailTagService;
import com.ys.util.shiro.ShiroUtils;
import com.ys.vo.R;

@Service("mailTagService")
public class MailTagServiceImpl implements MailTagService {
	@Autowired
	private MailTagMapper mailTagMapper;

	@Override
	@Transactional
	public R add(String name) {
		
		if (name == null || name.length() == 0) {
			return R.error("组名不能为空");
		}
		
		String loginUserId = ShiroUtils.getUserId();
		TsUserChange tsUserChange = new TsUserChange().setUserId(loginUserId).setStatus(1).queryFirst();
		
		MailTag entity = null;
		{
			Long createChangeId = tsUserChange.getId();
			entity = MailTag.mailTag(name, createChangeId, 1);
			mailTagMapper.insert(entity);
		}
		
		return R.ok();
	}

	@Override
	public R edit(Long id, String name) {
		
		MailTag entity = new MailTag().setId(id).queryFirst();

		entity.setName(name);
		mailTagMapper.update(entity);
		
		return R.ok();
	}
}
